<!--
 * @Author: lisong
 * @Date: 2023-04-17 16:22:20
 * @LastEditors: lisong
 * @LastEditTime: 2023-04-24 16:38:38
 * @Description: 收支预算表格
-->
<template>
  <rk-grid ref="rkGridRef"
           title="收支预算明细（单位：万元）"
           :data="tableData"
           :seqConfig="false"
           :toolbarConfig="true"
           :pagerConfig="false"
           :editConfig="true"
           :keepSource="true"
           :columns="columns">
    <template #toolbar_title_buttons>
      <el-button type="primary"
                 plain
                 @click="interestCalculation">利息测算
      </el-button>
      <el-button type="primary"
                 plain
                 @click="modelDownload">
        模板下载
      </el-button>
      <el-button type="primary"
                 plain
                 @click="importFile">导入
      </el-button>
      <el-button type="primary"
                 plain
                 @click="fillingInstructions">填报说明
      </el-button>
      <input type="file" ref="fileInputRef" accept=".xls, .xlsx" style="display: none"
             @change="fileInputChange"/>
    </template>
    <template #rk_type_name="{ row, column }">
      <div class="bgc full-size align-left">
        {{ row[column.field] }}
      </div>
    </template>
    <template #rk_formula="{ row, column }">
      <div class="bgc full-size align-left">
        {{ row[column.field] }}
      </div>
    </template>
    <template #rk_sr_input="{ row, column }">
      <div class="bgc full-size ">
        {{ formatAmount(row[column.field]) }}
      </div>
    </template>
    <template #rk_zc_input="{ row,column }">
      <div class="bgc full-size ">
        {{ formatAmount(row[column.field]) }}
      </div>
    </template>
    <template v-for="item in handleSlotName().srDefaults" v-slot:[item]="{ row,column }">
      <div :class="[row.TRUN_BG_COLOR===1?'bgc':'','full-size']">
        {{
          row[column.field] ? formatAmount(row[column.field]) : (row.IS_SR_EDIT !== 1 ? '--' : formatAmount(row[column.field]))
        }}
      </div>
    </template>
    <template v-for="item in handleSlotName().srEdits" v-slot:[item]="{ row,column }">
      <div :class="row.TRUN_BG_COLOR===1?'bgc':''" class="full-size">
        <div v-if="row.IS_SR_EDIT===1" class="full-size">
          <vxe-input v-model="row[column.field]" type="text" @blur="blurEvent(row,column)" clearable></vxe-input>
        </div>
        <div v-else class="full-size">
          {{
            row[column.field] ? formatAmount(row[column.field]) : (row.IS_SR_EDIT !== 1 ? '--' : formatAmount(row[column.field]))
          }}
        </div>
      </div>
    </template>
    <template v-for="item in handleSlotName().zcDefaults" v-slot:[item]="{ row,column }">
      <div :class="row.TRUN_BG_COLOR===1?'bgc':''" class="full-size">
        {{
          row[column.field] ? formatAmount(row[column.field]) : (row.IS_ZC_EDIT !== 1 ? '--' : formatAmount(row[column.field]))
        }}
      </div>
    </template>
    <template v-for="item in handleSlotName().zcEdits" v-slot:[item]="{ row,column }">
      <div :class="row.TRUN_BG_COLOR===1?'bgc':''" class="full-size">
        <div v-if="row.IS_ZC_EDIT===1 && row.TRUN_BG_COLOR!==1" class="full-size">
          <vxe-input v-model="row[column.field]" type="text" @blur="blurEvent(row,column)" clearable></vxe-input>
        </div>
        <div v-else class="full-size">
          {{
            row[column.field] ? formatAmount(row[column.field]) : (row.IS_ZC_EDIT !== 1 ? '--' : formatAmount(row[column.field]))
          }}
        </div>
      </div>
    </template>
  </rk-grid>
  <!-- <div class="app-container">
    <div class="VFormTable-container">
    </div>
  </div> -->
</template>

<script setup name="ProjectSzysTable">
import SzysTableData from '@/mock/SzysTableData.json'
import {getCurrentInstance, nextTick, onMounted, ref, watch} from 'vue';
import {uploadSzysFile} from "@/api/api-file";
import {queryBgtBalanceByProId} from "@/api/api-project";
import {formatAmount} from "@/utils/common/formatAmountUtil";

const {appContext} = getCurrentInstance();
const globalProxy = appContext.config.globalProperties;
// 向上触发的方法
const emits = defineEmits([
  'setFormItemValue'
])
const formulas = ref(null)
const props = defineProps({
  // 组件的名称，用于组织插槽数据，提供给表单设计器以及渲染器（必须定义）
  title: {type: String, default: '收支预算表格'},
  // 表单数据信息
  formData: {type: Object, default: {}}
})
const tableData = ref([])

// 表格的模板引用
const rkGridRef = ref(null)
const fileInputRef = ref(null)

// ----- 监听数据
// 监听表单 PRO_BUID_TERM 建设期限字段数据进行联动
watch(
    () => props.formData.PRO_BUID_TERM,
    (newValue, oldValue) => {
      console.log('PRO_BUID_TERM', newValue)
      handleDynamicColumn()
    },
    {deep: false, immediate: false}
)
// 监听表单 PRO_OPER_TERM 运营期限字段数据进行联动
watch(
    () => props.formData.PRO_OPER_TERM,
    (newValue, oldValue) => {
      console.log('PRO_OPER_TERM', newValue)
      handleDynamicColumn()
    },
    {deep: false, immediate: false}
)

// ----- 表格相关操作
/**
 * 表格列
 * @type {Ref<UnwrapRef<*[]>>}
 */
const columns = ref([])

/**
 * 基础列数据
 * @type {[{slots: {default: string}, field: string, width: number, title: string, align: string}, {slots: {default: string}, field: string, width: number, title: string, align: string}, {field: string, children: [{formatter: string[], slots: {default: string}, field: string, width: number, title: string, align: string}, {formatter: string[], slots: {default: string}, field: string, width: number, title: string, align: string}], width: number, sortable: boolean, title: string}]}
 */
const columnsBasic = [{
  field: 'BAL_TYPE_NAME',
  title: '收支类别',
  width: 200,
  align: 'left',
  slots: {default: 'rk_type_name'}
},
  {field: 'BAL_FORMULA', title: '公式', width: 160, align: 'left', slots: {default: 'rk_formula'}},
  {
    field: "TOTAL", title: "合计", width: 300, sortable: false,
    children: [
      {
        field: 'SRAMT_Y',
        title: '收入',
        width: 150,
        align: "right",
        formatter: ['formatAmountBit'],
        slots: {default: 'rk_sr_input'}
      },
      {
        field: 'ZCAMT_Y',
        title: '支出',
        width: 150,
        align: "right",
        formatter: ['formatAmountBit'],
        slots: {default: 'rk_zc_input'}
      },
    ]
  }]

/**
 * 模板下载
 */
const modelDownload = () => {
  window.location.href = "/api/proResApply/szysTemplateDownLoad"
}

/**
 * 处理动态列
 */
const handleDynamicColumn = () => {
  columns.value = [...columnsBasic]
  // 建设期限，运营期限
  const {PRO_BUID_TERM, PRO_OPER_TERM} = props.formData
  let tremNum = Number(PRO_BUID_TERM) + Number(PRO_OPER_TERM)
  if (!tremNum) {
    tremNum = 4
  }
  if (tremNum > 30) tremNum = 30
  let cDate = new Date()
  let yearStr = cDate.getFullYear() + "";
  let templateCol = {
    field: "TOTAL_Y23", title: "2023", width: 300, sortable: false,
    children: [
      {
        field: 'SRAMT_Y23',
        title: '收入',
        width: 150,
        align: "right",
        formatter: ['formatAmountBit'],
        editRender: {autofocus: '.el-input__inner'},
        slots: {default: 'rk_sr_23_input', edit: 'rk_sr_23_input_edit'}
      },
      {
        field: 'ZCAMT_Y23',
        title: '支出',
        width: 150,
        align: "right",
        formatter: ['formatAmountBit'],
        editRender: {autofocus: '.el-input__inner'},
        slots: {default: 'rk_zc_23_input', edit: 'rk_zc_23_input_edit'}
      },
    ]
  }
  for (let i = 0; i <= tremNum; i++) {
    let yFullName = Number(yearStr) + i
    let tempCol = Object.assign({}, templateCol, {
      field: `TOTAL_Y${i}`, title: yFullName,
    })
    let tempChild_0 = Object.assign({}, tempCol.children[0], {
      field: `SRAMT_Y${i}`,
      slots: {default: `rk_sr_${i}_input`, edit: `rk_sr_${i}_input_edit`}
    })
    let tempChild_1 = Object.assign({}, tempCol.children[1], {
      field: `ZCAMT_Y${i}`,
      slots: {default: `rk_zc_${i}_input`, edit: `rk_zc_${i}_input_edit`}
    })
    Object.assign(tempCol, {children: [tempChild_0, tempChild_1]})
    columns.value.push(tempCol)
  }
}

/**
 * 动态处理插槽
 * @returns {{zcDefaults: *[], zcEdits: *[], srDefaults: *[], srEdits: *[]}}
 */
const handleSlotName = () => {
  // 建设期限，运营期限
  const {PRO_BUID_TERM, PRO_OPER_TERM} = props.formData
  let tremNum = (Number(PRO_BUID_TERM) || 0) + (Number(PRO_OPER_TERM) || 0)
  if (!tremNum || tremNum === 0) {
    tremNum = 4
  }
  if (tremNum > 30) tremNum = 30
  let srDefaults = []
  let srEdits = []
  let zcDefaults = []
  let zcEdits = []
  for (let i = 0; i <= tremNum; i++) {
    srDefaults.push(`rk_sr_${i}_input`)
    srEdits.push(`rk_sr_${i}_input_edit`)
    zcDefaults.push(`rk_zc_${i}_input`)
    zcEdits.push(`rk_zc_${i}_input_edit`)
  }
  return {
    srDefaults,
    srEdits,
    zcDefaults,
    zcEdits
  }
}
/**
 * 初始化计算公式
 */
const initFormulas = () => {
  let tempFormulas = {}
  SzysTableData.forEach(item => {
    if (item.BAL_FORMULA && item.BAL_FORMULA.includes("=")) {
      //去除空格
      let trimFormulaStr = item.BAL_FORMULA.trim()
      let s = trimFormulaStr.split("=")
      if (s && s.length === 2) {
        let calculationRules = [trimFormulaStr]
        let strs = s[1].split(/(\-|\+|\*|\/)/);
        calculationRules.push(...strs)
        tempFormulas[s[0]] = calculationRules
        let params = s[1].split(/[-+*/]/)
        params.forEach(param => {
          tempFormulas[param] = calculationRules
        })
      }
      formulas.value = tempFormulas
    }
  })
}

/**
 * 计算行总支出/总收入
 * @param row
 * @param colName
 * @returns {{zc: number, sr: number}}
 */
const calculateRowTotalAmt = (row, colName) => {
  // 建设期限，运营期限
  const {PRO_BUID_TERM, PRO_OPER_TERM} = props.formData
  let tremNum = Number(PRO_BUID_TERM) + Number(PRO_OPER_TERM)
  if (!tremNum) {
    tremNum = 4
  }
  let totalMoney = {sr: 0, zc: 0}
  let tempRow = Object.assign({}, row)
  for (let i = 0; i <= tremNum; i++) {
    if (colName.includes("SRAMT_Y")) {
      totalMoney.sr += Number(tempRow[`SRAMT_Y${i}`]) || 0
    } else if (colName.includes("ZCAMT_Y")) {
      totalMoney.zc += Number(tempRow[`ZCAMT_Y${i}`]) || 0
    }
  }
  totalMoney.sr = totalMoney.sr || tempRow['SRAMT_Y']
  totalMoney.zc = totalMoney.zc || tempRow['ZCAMT_Y']
  return totalMoney
}

/**
 * 计算
 * @param row
 * @param column
 */
const calculate = async (row, column) => {
  if (!formulas.value) {
    initFormulas()
  }
  let formulaArray = formulas.value[row.BAL_FORMULA]
  if (!formulaArray) {
    const {zc, sr} = calculateRowTotalAmt(row, column.field)
    if (column.field.includes("SRAMT_Y")) {
      row["SRAMT_Y"] = sr
    } else if (column.field.includes("ZCAMT_Y")) {
      row["ZCAMT_Y"] = zc
    }
    if (rkGridRef.value.reloadRow)
      await rkGridRef.value.reloadRow(row)
  } else {
    let formula = formulaArray[0]
    const {tableData} = rkGridRef.value.getTableData()
    let totalAmtRow = tableData.filter(item => {
      return item.BAL_FORMULA.trim() === formula
    })
    if (!totalAmtRow || !totalAmtRow[0]) {
      return;
    }
    let newRow = Object.assign({}, totalAmtRow)
    let totalMoney = 0
    let totalZCSR = {sr: 0, zc: 0}
    let operator = ""
    //计算行的总支出总收入
    let rowTotalMoney = calculateRowTotalAmt(row, column.field)
    for (let i = 1; i < formulaArray.length; i++) {
      if (i % 2 === 0) {
        operator += formulaArray[i]
      } else {
        let cellValue = 0
        let cRow = tableData.filter(item => {
          return item.BAL_FORMULA.trim() === formulaArray[i]
        })
        if (!cRow || !cRow[0]) {
          return;
        }
        const {sr, zc} = calculateRowTotalAmt(cRow[0], column.field)
        totalZCSR.zc += Number(zc)
        totalZCSR.sr += Number(sr)
        cellValue = cRow[0][column.field] || 0
        totalMoney = operator === '-' ? (Number(totalMoney) - Number(cellValue)) : operator === '*' ? (Number(totalMoney) * Number(cellValue)) : operator === '/' ? (Number(totalMoney) / Number(cellValue)) : (Number(totalMoney) + Number(cellValue))
      }
    }
    if (column.field.includes("SRAMT_Y")) {
      row["SRAMT_Y"] = rowTotalMoney.sr
      if (row.BAL_FORMULA.trim() === 'I') {
        emitSetFormItemValue("BOND_FUND_AMT", row["SRAMT_Y"])
      }
      newRow[0]['SRAMT_Y'] = totalZCSR.sr
    } else if (column.field.includes("ZCAMT_Y")) {
      row["ZCAMT_Y"] = rowTotalMoney.zc
      newRow[0]['ZCAMT_Y'] = totalZCSR.zc
    }
    newRow[0][column.field] = totalMoney || 0
    if (rkGridRef.value.reloadRow) {
      await rkGridRef.value.reloadRow(newRow)
      await rkGridRef.value.reloadRow(row)
    }
  }
}

/**
 * 全局利息测算
 */
const interestCalculation = async () => {
  const {PRO_BUID_TERM: jsqx, PRO_OPER_TERM: yyqx} = props.formData
  let {tableData} = rkGridRef.value.getTableData();
  let cacheArray = []
  let zqfxMap = tableData[2];
  if (jsqx + yyqx <= 0) {
    globalProxy.$message.error("请输入项目建设期限和项目运营期限！");
    return;
  }
  // 获取每年专项债券还本额
  let zqhbMap = tableData[21];
  let qxStart = -1,
      qxEnd = -1;
  // 计算债券期限
  for (let i = 0; i <= jsqx + yyqx; i++) {
    // 最先发债年
    let syKey = 'SRAMT_Y' + i;
    if (Number(zqfxMap[syKey]) > 0 && qxStart < 0) {
      qxStart = i;
    }
    // 最后还本年
    let zcKey = 'ZCAMT_Y' + i;
    if (zqhbMap[zcKey] * 1 > 0) {
      qxEnd = i;
    }
  }
  // 债券发行期限 = 最后还本年 - 最先发债年
  let zqqx = qxEnd - qxStart;
  if (zqqx < 0) {
    globalProxy.$message.error("请输入地方政府债券发行额和专项债券还本额！");
    return
  }
  zqqx = jsqx + yyqx;
  // 债券利率
  let zqlv = zqqx > 5 ? 0.032 : 0.03;
  // 根据第一年债券发行，计算第二年付息
  let Amt_all = 0;
  for (let i = 0; i <= jsqx; i++) {
    // 计算建设期总金额
    let srKey = 'SRAMT_Y' + (i);
    Amt_all += tableData[2][srKey] * 1;
  }

  for (let i = 0; i <= zqqx; i++) {
    let zcKey = 'ZCAMT_Y' + (i + 1);
    tableData[9][zcKey] = 0;
    tableData[18][zcKey] = 0;
  }
  // 赋值合计金额
  tableData[9]['ZCAMT_Y'] = parseFloat((Amt_all * zqlv * jsqx).toString()).toFixed(2); //（二）财务费用-专项债券付息
  tableData[18]['ZCAMT_Y'] = parseFloat((Amt_all * zqlv * yyqx).toString()).toFixed(2); //（二）财务费用-专项债券付息支出
  await rkGridRef.value.reloadRow(tableData[9]);
  await rkGridRef.value.reloadRow(tableData[18]);
  for (const item of tableData) {
    const {sr} = calculateRowTotalAmt(item, 'SRAMT_Y')
    const {zc} = calculateRowTotalAmt(item, 'ZCAMT_Y')
    item['SRAMT_Y'] = sr
    item['ZCAMT_Y'] = zc
    if (!item.BAL_FORMULA.includes("=")) {
      if (!formulas.value) {
        initFormulas()
      }
      let formulaArray = formulas.value[item.BAL_FORMULA]
      if (formulaArray) {
        if (!cacheArray.includes(formulaArray[0])) {
          cacheArray.push(formulaArray[0])
          let totalAmtRow = tableData.filter(item => {
            return item.BAL_FORMULA.trim() === formulaArray[0]
          })
          let totalAmt = {sr: 0, zc: 0}
          for (let i = 1; i < formulaArray.length; i++) {
            if (i % 2 !== 0) {
              let cRow = tableData.filter(val => {
                return val.BAL_FORMULA.trim() === formulaArray[i]
              })
              const {sr} = calculateRowTotalAmt(cRow[0], 'SRAMT_Y')
              const {zc} = calculateRowTotalAmt(cRow[0], 'ZCAMT_Y')
              totalAmt.sr += Number(sr)
              totalAmt.zc += Number(zc)
            }
          }
          console.log(totalAmtRow[0].BAL_FORMULA, totalAmt);
          totalAmtRow[0]['SRAMT_Y'] = parseFloat(totalAmt.sr).toFixed(2)
          totalAmtRow[0]['ZCAMT_Y'] = parseFloat(totalAmt.zc).toFixed(2)
          await rkGridRef.value.reloadRow(totalAmtRow)
        }
      }
    }
    await rkGridRef.value.reloadRow(item)
  }
  globalProxy.$message.success("利息测算成功！！")
}
let headerJson = {
  "BAL_TYPE_NAME": "收支类别",
  "BAL_FORMULA": "公式",
  "SRAMT_Y": "收入求和",
  "ZCAMT_Y": "支出求和",
  "SRAMT_Y0": "T年收入金额",
  "ZCAMT_Y0": "T年支出金额",
  "SRAMT_Y1": "T+1年收入金额",
  "ZCAMT_Y1": "T+1年支出金额",
  "SRAMT_Y2": "T+2年收入金额",
  "ZCAMT_Y2": "T+2年支出金额",
  "SRAMT_Y3": "T+3年收入金额",
  "ZCAMT_Y3": "T+3年支出金额",
  "SRAMT_Y4": "T+4年收入金额",
  "ZCAMT_Y4": "T+4年支出金额",
  "SRAMT_Y5": "T+5年收入金额",
  "ZCAMT_Y5": "T+5年支出金额",
  "SRAMT_Y6": "T+6年收入金额",
  "ZCAMT_Y6": "T+6年支出金额",
  "SRAMT_Y7": "T+7年收入金额",
  "ZCAMT_Y7": "T+7年支出金额",
  "SRAMT_Y8": "T+8年收入金额",
  "ZCAMT_Y8": "T+8年支出金额",
  "SRAMT_Y9": "T+9年收入金额",
  "ZCAMT_Y9": "T+9年支出金额",
  "SRAMT_Y10": "T+10年收入金额",
  "ZCAMT_Y10": "T+10年支出金额",
  "SRAMT_Y11": "T+11年收入金额",
  "ZCAMT_Y11": "T+11年支出金额",
  "SRAMT_Y12": "T+12年收入金额",
  "ZCAMT_Y12": "T+12年支出金额",
  "SRAMT_Y13": "T+13年收入金额",
  "ZCAMT_Y13": "T+13年支出金额",
  "SRAMT_Y14": "T+14年收入金额",
  "ZCAMT_Y14": "T+14年支出金额",
  "SRAMT_Y15": "T+15年收入金额",
  "ZCAMT_Y15": "T+15年支出金额",
  "SRAMT_Y16": "T+16年收入金额",
  "ZCAMT_Y16": "T+16年支出金额",
  "SRAMT_Y17": "T+17年收入金额",
  "ZCAMT_Y17": "T+17年支出金额",
  "SRAMT_Y18": "T+18年收入金额",
  "ZCAMT_Y18": "T+18年支出金额",
  "SRAMT_Y19": "T+19年收入金额",
  "ZCAMT_Y19": "T+19年支出金额",
  "SRAMT_Y20": "T+20年收入金额",
  "ZCAMT_Y20": "T+20年支出金额",
  "SRAMT_Y21": "T+21年收入金额",
  "ZCAMT_Y21": "T+21年支出金额",
  "SRAMT_Y22": "T+22年收入金额",
  "ZCAMT_Y22": "T+22年支出金额",
  "SRAMT_Y23": "T+23年收入金额",
  "ZCAMT_Y23": "T+23年支出金额",
  "SRAMT_Y24": "T+24年收入金额",
  "ZCAMT_Y24": "T+24年支出金额",
  "SRAMT_Y25": "T+25年收入金额",
  "ZCAMT_Y25": "T+25年支出金额",
  "SRAMT_Y26": "T+26年收入金额",
  "ZCAMT_Y26": "T+26年支出金额",
  "SRAMT_Y27": "T+27年收入金额",
  "ZCAMT_Y27": "T+27年支出金额",
  "SRAMT_Y28": "T+28年收入金额",
  "ZCAMT_Y28": "T+28年支出金额",
  "SRAMT_Y29": "T+29年收入金额",
  "ZCAMT_Y29": "T+29年支出金额",
  "SRAMT_Y30": "T+30年收入金额",
  "ZCAMT_Y30": "T+30年支出金额"
}

const importFile = () => {
  fileInputRef.value.click()
}
const copyData = (data) => {
  let tempRows = []
  for (let row of SzysTableData) {
    let cRow = data.filter(item => {
      return item.BAL_FORMULA.trim() === row.BAL_FORMULA.trim()
    })
    let tempRow = row
    if (cRow && cRow[0]) {
      tempRow = Object.assign({}, cRow[0], row)
    }
    for (let key in tempRow) {
      if (key.includes("SRAMT_Y") || key.includes("SRAMT_Y")) {
        tempRow[key] = tempRow[key]
      }
    }
    tempRows.push(tempRow)
  }
  return tempRows;
}
const fileInputChange = async (e) => {
  let files = e.target.files
  let rowFile = files[0]
  if (!rowFile) return
  let formData = new FormData();
  formData.append('excelFile', rowFile)
  formData.append('headerJson', JSON.stringify(headerJson))
  formData.append('headerRowNumber', 2)
  const resp = await uploadSzysFile(formData)
  fileInputRef.value.value = null


  if (resp && resp.length > 0) {
    globalProxy.$message.success("导入成功")
    let tempRows = copyData(resp);
    rkGridRef.value.reloadData(tempRows)
  } else {
    globalProxy.$message.success("导入失败,未能匹配到数据!")
  }
}
const fillingInstructions = () => {
  window.open('/html/szys-tbsm.html', '_blank')
}
const blurEvent = (row, column) => {
  calculate(row, column)
}

const loadData = async () => {
  const {proId} = props.formData
  if (proId) {
    const resp = await queryBgtBalanceByProId({proId, proTypeId: ''})
    if (resp.code === 200) {
      let tempRows = copyData(resp.data);
      rkGridRef.value.reloadData(tempRows)
    } else {
      globalProxy.$message.error(resp.msg)
      tableData.value = SzysTableData
    }
  } else {
    tableData.value = SzysTableData
  }
}

onMounted(() => {
  loadData()
  handleDynamicColumn()
})

// ----- emits 方法定义
/**
 * 向上触发的方法，修改表单中的字段信息
 *
 * @param {String} fieldName 字段名称
 * @param {String} fieldValue 字段值
 */
const emitSetFormItemValue = function (fieldName, fieldValue) {
  emits('setFormItemValue', fieldName, fieldValue)
}

// ----- 获取组件数据
/**
 * 获取收支预算数据的方法，暴露给表单调用，固定名称getCompData
 */
const getCompData = function () {
  const {tableData} = rkGridRef.value.getTableData()
  //数据过滤过滤掉隐藏列的数据
  const {PRO_BUID_TERM, PRO_OPER_TERM} = props.formData
  let zqqx = Number(PRO_BUID_TERM + PRO_OPER_TERM) || 4
  tableData.forEach(item => {
    for (let itemKey in item) {
      if (itemKey.includes('SRAMT_Y') || itemKey.includes('SRAMT_Y')) {
        let year = Number(itemKey.replace("SRAMT_Y" || "ZCAMT_Y", "")) || 0
        if (year > zqqx) {
          item[itemKey] = 0
        }
      }
    }
  })
  return {
    'bgtbalance_data': JSON.parse(JSON.stringify(tableData))
  }
}

defineExpose({
  getCompData
})


</script>

<style lang="scss" scoped>
.operation-box {
  display: flex;
  justify-content: space-around;
}

.VFormTable-container {
  height: 500px;
}

.vform-table-search {
  margin-right: 15px;
}

.full-size {
  position: absolute;
  width: calc(100% - 1px);
  height: calc(100% - 1px);
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
}

.bgc {
  background-color: #e6e6e6;
}

.align-left {
  justify-content: flex-start;
}
</style>
